package com.xt.mvcpilot.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.security.authentication.encoding.PasswordEncoder;

import com.xt.mvcpilot.data.User;
import com.xt.mvcpilot.dao.UserDao;
import com.xt.mvcpilot.dao.impl.AppBasicDaoImpl;


/**
 * class for the xtmvcpilot application
 * 
 * hibernate implementation dao class to get User information
 * 
 * @author txiao
 * @version Revision: 1.0, Date: 07.06.2011
 *
 */
@Repository("userDao")
public class UserDaoImpl extends AppBasicDaoImpl<User, Long> implements UserDao{
	
	@Autowired
	private PasswordEncoder passwordEncoder;
	
	public UserDaoImpl(){		
		super(User.class);
	}
	
	@Override
	public User save(User user){
		//encode password
		user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
		super.save(user);
		return user;
	}

	public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
		this.passwordEncoder = passwordEncoder;
	}
	
}
